package com.huluobo.a2201mvvm_imdemo.register;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.a2201mvvm_imdemo.bean.UserBean;
import com.huluobo.a2201mvvm_imdemo.mvvm.BaseRepo;
import com.hyphenate.exceptions.HyphenateException;

/**
 * Created by LC on 2024/3/22.
 */
public class RegisterRepo extends BaseRepo {
    public void register(String username, String password, MutableLiveData<UserBean> success,
                         MutableLiveData<String> failed) {
        new Thread(() -> {
            try {
                emClient.createAccount(username, password);
                //同步方法,如果程序能过走到这里,证明已经请求成功
                success.postValue(new UserBean(username, password));
            } catch (HyphenateException e) {
                //如果程序走到了catch,证明请求失败,失败就写在这里
                failed.postValue(e.getDescription());
                Log.i("TagA", "e:" + e.getErrorCode());
                throw new RuntimeException(e);
            }
        }).start();

    }
}
